package com.symaster.common.animation.view.frame;

import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
import com.symaster.common.animation.Curve;
import com.symaster.common.animation.CurvePoint;
import com.symaster.common.animation.CurveUtil;
import com.symaster.common.animation.view.CurveCreateMouseAdapter;
import com.symaster.common.animation.view.frame.theme.Theme;
import com.symaster.common.geom.entity.LineSegment;
import com.symaster.common.swing.util.SwingUtil;

import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;

/**
 * @author yinmiao
 * @version 2023/11/2
 */
public class CurveCreateView extends JDialog {
    static {
        Theme.setup();
    }

    private final CurveCreateCanvas curveCreateCanvas;

    private JPanel root_panel;
    private JPanel canvas_container;
    private JButton create_button;
    private JTextField p1_x_input;
    private JTextField p1_y_input;
    private JTextField p2_x_input;
    private JTextField p2_y_input;
    private JTextField p3_x_input;
    private JTextField p3_y_input;
    private JTextField p4_x_input;
    private JTextField p4_y_input;
    private JTextField p5_x_input;
    private JTextField p5_y_input;
    private List<CurvePoint> curvePoints; // 控制点列表
    private boolean create = false;

    public CurveCreateView() throws HeadlessException {
        setTitle("曲线构造器");
        this.curveCreateCanvas = new CurveCreateCanvas();
        canvas_container.add(curveCreateCanvas);
        setResizable(false);
        setContentPane(root_panel);
        setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        setPreferredSize(new Dimension(900, 600));
        pack();
        setModal(true);
        SwingUtil.toCenter(this);
        initListener();
    }

    private void initListener() {
        CurveCreateMouse curveCreateMouse = new CurveCreateMouse(this);
        curveCreateCanvas.addMouseListener(curveCreateMouse);
        curveCreateCanvas.addMouseMotionListener(curveCreateMouse);

        FocusAdapter focusAdapter = new FocusAdapter() {
            @Override
            public void focusLost(FocusEvent e) {
                inputToPoint();
            }
        };

        p1_x_input.addFocusListener(focusAdapter);
        p1_x_input.addFocusListener(focusAdapter);
        p1_y_input.addFocusListener(focusAdapter);
        p2_x_input.addFocusListener(focusAdapter);
        p2_y_input.addFocusListener(focusAdapter);
        p3_x_input.addFocusListener(focusAdapter);
        p3_y_input.addFocusListener(focusAdapter);
        p4_x_input.addFocusListener(focusAdapter);
        p4_y_input.addFocusListener(focusAdapter);
        p5_x_input.addFocusListener(focusAdapter);
        p5_y_input.addFocusListener(focusAdapter);

        create_button.addActionListener(e -> {
            create = true;
            dispose();
        });
    }

    private void inputToPoint() {
        float x1 = Float.parseFloat(p1_x_input.getText());
        float y1 = Float.parseFloat(p1_y_input.getText());
        float x2 = Float.parseFloat(p2_x_input.getText());
        float y2 = Float.parseFloat(p2_y_input.getText());
        float x3 = Float.parseFloat(p3_x_input.getText());
        float y3 = Float.parseFloat(p3_y_input.getText());
        float x4 = Float.parseFloat(p4_x_input.getText());
        float y4 = Float.parseFloat(p4_y_input.getText());
        float x5 = Float.parseFloat(p5_x_input.getText());
        float y5 = Float.parseFloat(p5_y_input.getText());

        curvePoints.get(0).setX(Math.min(Math.max(x1 / 100f, 0f), 1f));
        curvePoints.get(0).setY(Math.min(Math.max(y1 / 100f, 0f), 1f));
        curvePoints.get(1).setX(Math.min(Math.max(x2 / 100f, 0f), 1f));
        curvePoints.get(1).setY(Math.min(Math.max(y2 / 100f, 0f), 1f));
        curvePoints.get(2).setX(Math.min(Math.max(x3 / 100f, 0f), 1f));
        curvePoints.get(2).setY(Math.min(Math.max(y3 / 100f, 0f), 1f));
        curvePoints.get(3).setX(Math.min(Math.max(x4 / 100f, 0f), 1f));
        curvePoints.get(3).setY(Math.min(Math.max(y4 / 100f, 0f), 1f));
        curvePoints.get(4).setX(Math.min(Math.max(x5 / 100f, 0f), 1f));
        curvePoints.get(4).setY(Math.min(Math.max(y5 / 100f, 0f), 1f));
        updateBezier();
    }

    public static class CurveCreateMouse extends CurveCreateMouseAdapter {

        private final CurveCreateView curveCreateView;
        private CurvePoint selectCurvePoint;
        private Point selectMousePoint;
        private CurvePoint lastCurvePoint;

        public CurveCreateMouse(CurveCreateView curveCreateView) {
            this.curveCreateView = curveCreateView;
        }

        @Override
        public void mousePressed(MouseEvent e) {
            this.selectMousePoint = e.getPoint();
            this.selectCurvePoint = null;

            CurveCreateCanvas curveCreateCanvas = curveCreateView.curveCreateCanvas;
            List<CurvePoint> curvePoints1 = curveCreateView.curvePoints;

            int canvasWidth = curveCreateCanvas.getWidth();
            int canvasHeight = curveCreateCanvas.getHeight();

            for (CurvePoint curvePoint : curvePoints1) {
                float x = curvePoint.getX() * canvasWidth;
                float y = curvePoint.getY() * canvasHeight;

                if (x - 5 <= this.selectMousePoint.getX() &&
                        x + 5 >= this.selectMousePoint.getX() &&
                        y - 5 <= this.selectMousePoint.getY() &&
                        y + 5 >= this.selectMousePoint.getY()) {
                    this.selectCurvePoint = curvePoint;
                    this.lastCurvePoint = new CurvePoint(x, y);
                    break;
                }
            }
        }

        @Override
        public void mouseDragged(MouseEvent e) {
            if (selectMousePoint != null && selectCurvePoint != null) {
                int canvasWidth = curveCreateView.curveCreateCanvas.getWidth();
                int canvasHeight = curveCreateView.curveCreateCanvas.getHeight();

                Point point = e.getPoint();
                double xVector = point.getX() - selectMousePoint.getX();
                double yVector = point.getY() - selectMousePoint.getY();

                float dstX = lastCurvePoint.getX() + (float) xVector;
                float dstY = lastCurvePoint.getY() + (float) yVector;

                selectCurvePoint.setX(Math.min(Math.max(dstX / canvasWidth, 0f), 1.0f));
                selectCurvePoint.setY(Math.min(Math.max(dstY / canvasHeight, 0f), 1.0f));

                curveCreateView.updateBezier();
            }
        }

        @Override
        public void mouseMoved(MouseEvent e) {
            Point point = e.getPoint();

            CurveCreateCanvas curveCreateCanvas = curveCreateView.curveCreateCanvas;
            List<CurvePoint> curvePoints = curveCreateView.curvePoints;

            int canvasWidth = curveCreateCanvas.getWidth();
            int canvasHeight = curveCreateCanvas.getHeight();

            Integer selectIndex = null;
            for (int i = 0; i < curvePoints.size(); i++) {
                CurvePoint curvePoint = curvePoints.get(i);
                float x = curvePoint.getX() * canvasWidth;
                float y = curvePoint.getY() * canvasHeight;
                // System.out.println(x + " :: " + y);

                if (x - 5 <= point.getX() &&
                        x + 5 >= point.getX() &&
                        y - 5 <= point.getY() &&
                        y + 5 >= point.getY()) {
                    selectIndex = i;
                    break;
                }
            }
            curveCreateCanvas.setSelectCurvePoint(selectIndex);
        }
    }

    private void initCurvePoints() {
        if (curvePoints == null) {
            curvePoints = new ArrayList<>();
        }
        curvePoints.add(new CurvePoint(0, 1f));
        curvePoints.add(new CurvePoint(0.25f, 0.75f));
        curvePoints.add(new CurvePoint(0.5f, 0.5f));
        curvePoints.add(new CurvePoint(0.75f, 0.25f));
        curvePoints.add(new CurvePoint(1f, 0f));

        updateBezier();
    }

    private void updateBezier() {
        p1_x_input.setText(Math.round(curvePoints.get(0).getX() * 100) + "");
        p1_y_input.setText(Math.round(curvePoints.get(0).getY() * 100) + "");
        p2_x_input.setText(Math.round(curvePoints.get(1).getX() * 100) + "");
        p2_y_input.setText(Math.round(curvePoints.get(1).getY() * 100) + "");
        p3_x_input.setText(Math.round(curvePoints.get(2).getX() * 100) + "");
        p3_y_input.setText(Math.round(curvePoints.get(2).getY() * 100) + "");
        p4_x_input.setText(Math.round(curvePoints.get(3).getX() * 100) + "");
        p4_y_input.setText(Math.round(curvePoints.get(3).getY() * 100) + "");
        p5_x_input.setText(Math.round(curvePoints.get(4).getX() * 100) + "");
        p5_y_input.setText(Math.round(curvePoints.get(4).getY() * 100) + "");

        curveCreateCanvas.updateCurvePoints(curvePoints);
        List<LineSegment> lineSegments = CurveUtil.getBezierLines(curvePoints.toArray(new CurvePoint[0]));
        curveCreateCanvas.updateLineSegments(lineSegments);
    }

    public Curve open() {
        initCurvePoints();
        setVisible(true);
        if (create) {
            return new Curve(curvePoints);
        } else {
            return null;
        }
    }

    {
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
        $$$setupUI$$$();
    }

    /**
     * Method generated by IntelliJ IDEA GUI Designer
     * >>> IMPORTANT!! <<<
     * DO NOT edit this method OR call it in your code!
     *
     * @noinspection ALL
     */
    private void $$$setupUI$$$() {
        root_panel = new JPanel();
        root_panel.setLayout(new BorderLayout(0, 0));
        final JPanel panel1 = new JPanel();
        panel1.setLayout(new GridLayoutManager(7, 1, new Insets(5, 0, 5, 5), -1, -1));
        panel1.setPreferredSize(new Dimension(200, 0));
        root_panel.add(panel1, BorderLayout.EAST);
        final Spacer spacer1 = new Spacer();
        panel1.add(spacer1, new GridConstraints(5, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
        final JPanel panel2 = new JPanel();
        panel2.setLayout(new BorderLayout(0, 0));
        panel1.add(panel2, new GridConstraints(6, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        create_button = new JButton();
        create_button.setLabel("Create");
        create_button.setText("Create");
        panel2.add(create_button, BorderLayout.CENTER);
        final JPanel panel3 = new JPanel();
        panel3.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
        panel1.add(panel3, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        final JPanel panel4 = new JPanel();
        panel4.setLayout(new GridLayoutManager(2, 1, new Insets(0, 0, 0, 0), -1, -1));
        panel3.add(panel4, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        panel4.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(new Color(-5658199)), "点1", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
        final JPanel panel5 = new JPanel();
        panel5.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1));
        panel4.add(panel5, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        final JLabel label1 = new JLabel();
        label1.setText("X");
        panel5.add(label1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        p1_x_input = new JTextField();
        panel5.add(p1_x_input, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
        final JPanel panel6 = new JPanel();
        panel6.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1));
        panel4.add(panel6, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        final JLabel label2 = new JLabel();
        label2.setText("Y");
        panel6.add(label2, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        p1_y_input = new JTextField();
        panel6.add(p1_y_input, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
        final JPanel panel7 = new JPanel();
        panel7.setLayout(new GridLayoutManager(2, 1, new Insets(0, 0, 0, 0), -1, -1));
        panel1.add(panel7, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        panel7.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(new Color(-5658199)), "点2", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
        final JPanel panel8 = new JPanel();
        panel8.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1));
        panel7.add(panel8, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        final JLabel label3 = new JLabel();
        label3.setText("X");
        panel8.add(label3, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        p2_x_input = new JTextField();
        panel8.add(p2_x_input, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
        final JPanel panel9 = new JPanel();
        panel9.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1));
        panel7.add(panel9, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        final JLabel label4 = new JLabel();
        label4.setText("Y");
        panel9.add(label4, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        p2_y_input = new JTextField();
        panel9.add(p2_y_input, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
        final JPanel panel10 = new JPanel();
        panel10.setLayout(new GridLayoutManager(2, 1, new Insets(0, 0, 0, 0), -1, -1));
        panel1.add(panel10, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        panel10.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(new Color(-5658199)), "点3", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
        final JPanel panel11 = new JPanel();
        panel11.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1));
        panel10.add(panel11, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        final JLabel label5 = new JLabel();
        label5.setText("X");
        panel11.add(label5, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        p3_x_input = new JTextField();
        panel11.add(p3_x_input, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
        final JPanel panel12 = new JPanel();
        panel12.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1));
        panel10.add(panel12, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        final JLabel label6 = new JLabel();
        label6.setText("Y");
        panel12.add(label6, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        p3_y_input = new JTextField();
        panel12.add(p3_y_input, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
        final JPanel panel13 = new JPanel();
        panel13.setLayout(new GridLayoutManager(2, 1, new Insets(0, 0, 0, 0), -1, -1));
        panel1.add(panel13, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        panel13.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(new Color(-5658199)), "点4", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
        final JPanel panel14 = new JPanel();
        panel14.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1));
        panel13.add(panel14, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        final JLabel label7 = new JLabel();
        label7.setText("X");
        panel14.add(label7, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        p4_x_input = new JTextField();
        panel14.add(p4_x_input, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
        final JPanel panel15 = new JPanel();
        panel15.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1));
        panel13.add(panel15, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        final JLabel label8 = new JLabel();
        label8.setText("Y");
        panel15.add(label8, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        p4_y_input = new JTextField();
        panel15.add(p4_y_input, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
        final JPanel panel16 = new JPanel();
        panel16.setLayout(new GridLayoutManager(2, 1, new Insets(0, 0, 0, 0), -1, -1));
        panel1.add(panel16, new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        panel16.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(new Color(-5658199)), "点5", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
        final JPanel panel17 = new JPanel();
        panel17.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1));
        panel16.add(panel17, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        final JLabel label9 = new JLabel();
        label9.setText("X");
        panel17.add(label9, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        p5_x_input = new JTextField();
        panel17.add(p5_x_input, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
        final JPanel panel18 = new JPanel();
        panel18.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1));
        panel16.add(panel18, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        final JLabel label10 = new JLabel();
        label10.setText("Y");
        panel18.add(label10, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        p5_y_input = new JTextField();
        panel18.add(p5_y_input, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
        final JPanel panel19 = new JPanel();
        panel19.setLayout(new GridLayoutManager(1, 1, new Insets(5, 5, 5, 5), -1, -1));
        root_panel.add(panel19, BorderLayout.CENTER);
        canvas_container = new JPanel();
        canvas_container.setLayout(new BorderLayout(0, 0));
        panel19.add(canvas_container, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        canvas_container.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), null, TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
    }

    /**
     * @noinspection ALL
     */
    public JComponent $$$getRootComponent$$$() {
        return root_panel;
    }

}
